#include <stdio.h>

int searchInsert(int * nums, int numsSize, int target)
{
    int left = 0;
    int right = numsSize - 1;
    while (left <= right)
    {
        int mid = left + (right - left) / 2;
        if (nums[mid] ==  target)
        {
            return mid;//find target
        }
        else if (nums[mid] < target)
        {
            left = mid + 1;//adjust the lower bound of the search range
        }
        else if (nums[mid] > target)
        {
            right = mid - 1;//adjust the higher bound
        }
    }

    return left;

}

int main() {
    int nums[] = {1, 3, 5, 6}; 
    int target = 7; // target
    int numsSize = sizeof(nums) / sizeof(nums[0]); // 数组长度

    printf("Target insert position: %d\n", searchInsert(nums, numsSize, target));

    return 0;
}